<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../../../../../miniUI/scripts/boot.js"></script>
    <script src="../../../../../../../pdfjs/build/pdf.js"></script>
</head>
<body>
<form action="" enctype="multipart/form-data" method="post">
    上传文件：<input type="file" name="file" id="fileId"><br/>
    <input type="button" value="提交" onclick="upload()">
</form>

<input type="text" id="filePath"/><input type="button" value="下载" id="downloadId" onclick="download()"/>
<input type="text" id="preview"/><input type="button" value="文件预览" id="previewId" onclick="preview()"/>
<div title="center" region="center" id="centerId">
    <!--<iframe src="/RTPKSPS-KSS/miniUI/frame/pages/base/resource/pages/viewer.html?file=http://localhost:8888/files/preview/64f389d5ef3048108db61b4484bf3d01"-->
    <iframe src="http://localhost:8080/DSMP/pdfjs/web/viewer.html"
            style="width: 100%;height: 900pt" id="iframeId" name="iframe"></iframe>
</div>
</body>
<script>
    function upload() {
        var type = "file";          //后台接收时需要的参数名称，自定义即可
        var id = "fileId";            //即input的id，用来寻找值
        var formData = new FormData();
        formData.append(type, $("#" + id)[0].files[0]);    //生成一对表单属性
        $.ajax({
            type: "POST",           //因为是传输文件，所以必须是post
            url: 'http://localhost:8080/DSMP/upload',         //对应的后台处理类的地址
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                alert(data.msg);
            }
        });
    }


    function download() {
        var filePath = document.getElementById("filePath").value
        console.log(filePath)
        window.open("http://localhost:8080/DSMP/download?filePath=" + filePath, "下载", filePath)
    }


    function preview() {
        var iframe = document.getElementById("iframeId");
            alert(111)
        var id = document.getElementById("previewId").value
        srcUrl = 'http://localhost:8080/DSMP/pdfjs/web/viewer.html?file?file=http://localhost:8080/docFile/preview/' + id;
        iframe.setAttribute("src", srcUrl)

    }
</script>
</html>